<template>
	<view class="px-12 ">
		<y-tabs :list='tabList' v-model="type" @change="paging.reload()"></y-tabs>
		<z-paging ref="paging" v-model="list" @query="getList" use-page-scroll>
			<view class="pt-10">
				<template v-if='type=="oralCopy"'>
					<resultOralCopy :list='list' @more="open" />
				</template>
				<template v-if='type=="facialFusion"'>
					<view class="pb-6">
						<text class="fs-13 text-999">长按图片保存到本地</text>
					</view>
					<resultFacialFusion :list="list" @more="open" />
				</template>
				
				<template v-if='type=="hairStyle"'>
					<view class="pb-6">
						<text class="fs-13 text-999">长按图片保存到本地</text>
					</view>
					<resultHairStyle :list='list' @more="open" />
				</template>
				
				<template v-if='type=="oldPhotoRestoration"'>
					<view class="pb-6">
						<text class="fs-13 text-999">长按图片保存到本地</text>
					</view>
					<resultOldPhotoRestoration :list='list' @more="open" />
				</template>
				
				<template v-if='type=="photoHD"'>
					<view class="pb-6">
						<text class="fs-13 text-999">长按图片保存到本地</text>
					</view>
					<resultPhotoHd :list='list' @more="open" />
				</template>
			</view>
		</z-paging>

		<y-popup ref="morePopup" mode="bottom" round='16px'>
			<view class='text-center fs-15 round-top-10 '>
				<view class="wa  py-15 border-bottom-f1 text-red " @click="del">删除</view>
				<view class="wa  py-15 border-bottom-f1  " @click="morePopup.close()">取消</view>
			</view>
		</y-popup>
	</view>
</template>

<script setup>
	import useZPaging from "@/uni_modules/z-paging/components/z-paging/js/hooks/useZPaging.js";
	import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
	import { ref, reactive } from 'vue';
	import { record, delRecord } from '@/api/app.js'
	import { onLoad } from '@dcloudio/uni-app'
	import resultFacialFusion from "./modules/result-facial-fusion.vue";
	import resultOralCopy from "./modules/result-oral-copy.vue";
	import resultHairStyle from "./modules/result-hair-style.vue";
	import resultPhotoHd from "./modules/result-photo-hd.vue";
	import resultOldPhotoRestoration from "./modules/result-old-photo-restoration.vue";
	import { $tool } from "@/utils";
	const tabList = reactive([
		{ label: 'AI文案', value: 'oralCopy' },
		{ label: '人脸融合', value: 'facialFusion' },
		{ label: '人物换发型', value: 'hairStyle' },
		{ label: '老照片修复', value: 'oldPhotoRestoration' },
		{ label: '照片高清化', value: 'photoHD' },
	])
	const morePopup = ref()
	const list = ref()
	const paging = ref()
	const type = ref('oralCopy')
	useZPaging(paging)

	const getList = (page, limit) => {
		record({ page: page, limit: limit, type: type.value }).then(res => {
			paging.value.complete(res.data)
		})
	}
	const detail = ref()
	const open = (e) => {
		detail.value = e
		morePopup.value.open()
	}

	const del = () => {
		uni.showModal({
			title: '确认删除',
			content: '确认删除，删除后无法恢复',
			success(res) {
				if (res.confirm) {
					delRecord({ id: detail.value.id }).then(res => {
						$tool.toast('删除成功');
						morePopup.value.close()
						paging.value.reload()
					})
				}
			}
		})
	}

	const download = async () => {
		// #ifdef MP-WEIXIN
		const res = uni.downloadFile({
			url: detail.value.result
		})
		uni.saveImageToPhotosAlbum({
			filePath: res.tempFilePath
		})
		// #endif

	}
</script>

<style>

</style>